

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  <meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  
  <title>CephFS 快照 &mdash; Ceph Documentation</title>
  

  
  <link rel="stylesheet" href="../../_static/ceph.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/ceph.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/graphviz.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" />

  
  

  
  

  

  
  <!--[if lt IE 9]>
    <script src="../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
        <script src="../../_static/jquery.js"></script>
        <script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script>
        <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
        <script src="../../_static/doctools.js"></script>
        <script src="../../_static/sphinx_highlight.js"></script>
    
    <script type="text/javascript" src="../../_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="../../genindex/" />
    <link rel="search" title="Search" href="../../search/" />
    <link rel="next" title="Ceph 文件系统客户端的驱逐" href="../eviction/" />
    <link rel="prev" title="多活 MDS 守护进程的配置" href="../multimds/" /> 
</head>

<body class="wy-body-for-nav">

   
  <header class="top-bar">
    <div role="navigation" aria-label="Page navigation">
  <ul class="wy-breadcrumbs">
      <li><a href="../../" class="icon icon-home" aria-label="Home"></a></li>
          <li class="breadcrumb-item"><a href="../">Ceph 文件系统</a></li>
      <li class="breadcrumb-item active">CephFS 快照</li>
      <li class="wy-breadcrumbs-aside">
            <a href="../../_sources/cephfs/snapshots.rst.txt" rel="nofollow"> View page source</a>
      </li>
  </ul>
  <hr/>
</div>
  </header>
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search"  style="background: #eee" >
          

          
            <a href="../../" class="icon icon-home"> Ceph
          

          
          </a>

          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search/" method="get">
    <input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../start/">Ceph 简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../install/">安装 Ceph</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../cephadm/">Cephadm</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../rados/">Ceph 存储集群</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../">Ceph 文件系统</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../#cephfs">CephFS 入门</a></li>
<li class="toctree-l2"><a class="reference internal" href="../#id4">管理</a></li>
<li class="toctree-l2"><a class="reference internal" href="../#id5">挂载 CephFS</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="../#id6">CephFS 内幕</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="../mds-states/"> MDS 的各种状态</a></li>
<li class="toctree-l3"><a class="reference internal" href="../posix/"> POSIX 兼容性</a></li>
<li class="toctree-l3"><a class="reference internal" href="../mds-journaling/"> MDS 日志记录</a></li>
<li class="toctree-l3"><a class="reference internal" href="../file-layouts/"> 文件布局</a></li>
<li class="toctree-l3"><a class="reference internal" href="../mdcache/"> 分布式元数据缓存</a></li>
<li class="toctree-l3"><a class="reference internal" href="../dynamic-metadata-management/"> CephFS 内的动态元数据管理</a></li>
<li class="toctree-l3"><a class="reference internal" href="../cephfs-io-path/"> CephFS IO 路径</a></li>
<li class="toctree-l3"><a class="reference internal" href="../charmap/"> 大小写敏感和规范化</a></li>
<li class="toctree-l3"><a class="reference internal" href="../lazyio/"> LazyIO</a></li>
<li class="toctree-l3"><a class="reference internal" href="../dirfrags/"> 目录分片的配置</a></li>
<li class="toctree-l3"><a class="reference internal" href="../multimds/"> 多活 MDS 的配置</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#"> 快照</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#id1">创建快照</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id2">用快照恢复数据</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id3">删除快照</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../#id7">故障排除和灾难恢复</a></li>
<li class="toctree-l2"><a class="reference internal" href="../#id9">更多细节</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../rbd/">Ceph 块设备</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../radosgw/">Ceph 对象网关</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mgr/">Ceph 管理器守护进程</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mgr/dashboard/">Ceph 仪表盘</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../monitoring/">监控概览</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api/">API 文档</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../architecture/">体系结构</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../dev/developer_guide/">开发者指南</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../dev/internals/">Ceph 内幕</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../governance/">项目管理</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../foundation/">Ceph 基金会</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../ceph-volume/">ceph-volume</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../releases/general/">Ceph 版本（总目录）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../releases/">Ceph 版本（索引）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../security/">Security</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../hardware-monitoring/">硬件监控</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../glossary/">Ceph 术语</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../jaegertracing/">Tracing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../translation_cn/">中文版翻译资源</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../">Ceph</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
<div id="dev-warning" class="admonition note">
  <p class="first admonition-title">Notice</p>
  <p class="last">This document is for a development version of Ceph.</p>
</div>
  <div id="docubetter" align="right" style="padding: 5px; font-weight: bold;">
    <a href="https://pad.ceph.com/p/Report_Documentation_Bugs">Report a Documentation Bug</a>
  </div>

  
  <section id="cephfs">
<h1>CephFS 快照<a class="headerlink" href="#cephfs" title="Permalink to this heading"></a></h1>
<p>CephFS 快照可创建一个不可变的文件系统视图，让它定格在快照拍下的那个时间点。
CephFS 支持快照，快照在名为 <code class="docutils literal notranslate"><span class="pre">.snap</span></code> 的特殊隐藏子目录里面管理。
快照是用 <code class="docutils literal notranslate"><span class="pre">mkdir</span></code> 在这个目录内创建的。</p>
<p>快照可以用不同的名字暴露出来，更改下列客户端配置：</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">snapdirname</span></code> 它是内核客户端的一个挂载选项</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">client_snapdir</span></code> 它是 ceph-fuse 的一个挂载选项</p></li>
</ul>
<section id="id1">
<h2>创建快照<a class="headerlink" href="#id1" title="Permalink to this heading"></a></h2>
<p>新文件系统默认启用了 CephFS 快照功能。
要在现有文件系统上启用，用下列命令。</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$<span class="w"> </span>ceph<span class="w"> </span>fs<span class="w"> </span><span class="nb">set</span><span class="w"> </span>&lt;fs_name&gt;<span class="w"> </span>allow_new_snaps<span class="w"> </span><span class="nb">true</span>
</pre></div>
</div>
<p>启用快照后， CephFS 内的所有目录都会有一个特殊的 <code class="docutils literal notranslate"><span class="pre">.snap</span></code> 目录。
（只要你想，还可以用客户端的 snapdir 选项配置不同的名字）。
要创建 CephFS 快照，只需在 <code class="docutils literal notranslate"><span class="pre">.snap</span></code> 下创建一个子目录，名字由你定。
例如，要给目录 <code class="docutils literal notranslate"><span class="pre">/file1/</span></code> 创建快照，调用 <code class="docutils literal notranslate"><span class="pre">mkdir</span> <span class="pre">/file1/.snap/snapshot-name</span></code> 。</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$<span class="w"> </span>touch<span class="w"> </span>file1
$<span class="w"> </span><span class="nb">cd</span><span class="w"> </span>.snap
$<span class="w"> </span>mkdir<span class="w"> </span>my_snapshot
</pre></div>
</div>
</section>
<section id="id2">
<h2>用快照恢复数据<a class="headerlink" href="#id2" title="Permalink to this heading"></a></h2>
<p>快照也能用于恢复删掉的文件。</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">创建文件</span> <span class="pre">file1</span> <span class="pre">，然后创建快照</span> <span class="pre">snap1</span></code></p></li>
</ul>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$<span class="w"> </span>touch<span class="w"> </span>/mnt/cephfs/file1
$<span class="w"> </span><span class="nb">cd</span><span class="w"> </span>.snap
$<span class="w"> </span>mkdir<span class="w"> </span>snap1
</pre></div>
</div>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">创建文件</span> <span class="pre">file2</span> <span class="pre">，然后创建快照</span> <span class="pre">snap2</span></code></p></li>
</ul>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$<span class="w"> </span>touch<span class="w"> </span>/mnt/cephfs/file2
$<span class="w"> </span><span class="nb">cd</span><span class="w"> </span>.snap
$<span class="w"> </span>mkdir<span class="w"> </span>snap2
</pre></div>
</div>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">删除</span> <span class="pre">file1</span> <span class="pre">，然后创建新快照</span> <span class="pre">snap3</span></code></p></li>
</ul>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$<span class="w"> </span>rm<span class="w"> </span>/mnt/cephfs/file1
$<span class="w"> </span><span class="nb">cd</span><span class="w"> </span>.snap
$<span class="w"> </span>mkdir<span class="w"> </span>snap3
</pre></div>
</div>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">恢复</span> <span class="pre">file1</span> <span class="pre">，用</span> <span class="pre">cp</span> <span class="pre">命令和快照</span> <span class="pre">snap2</span></code></p></li>
</ul>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$<span class="w"> </span><span class="nb">cd</span><span class="w"> </span>.snap
$<span class="w"> </span><span class="nb">cd</span><span class="w"> </span>snap2
$<span class="w"> </span>cp<span class="w"> </span>file1<span class="w"> </span>/mnt/cephfs/
</pre></div>
</div>
</section>
<section id="id3">
<h2>删除快照<a class="headerlink" href="#id3" title="Permalink to this heading"></a></h2>
<p>在目标目录里的 <code class="docutils literal notranslate"><span class="pre">.snap</span></code> 目录中调用 <code class="docutils literal notranslate"><span class="pre">rmdir</span></code> 可删除快照。
（如果一个目录的根里有快照，删除此目录会失败；
必须先删除快照）。</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$<span class="w"> </span><span class="nb">cd</span><span class="w"> </span>.snap
$<span class="w"> </span>rmdir<span class="w"> </span>my_snapshot
</pre></div>
</div>
</section>
</section>



<div id="support-the-ceph-foundation" class="admonition note">
  <p class="first admonition-title">Brought to you by the Ceph Foundation</p>
  <p class="last">The Ceph Documentation is a community resource funded and hosted by the non-profit <a href="https://ceph.io/en/foundation/">Ceph Foundation</a>. If you would like to support this and our other efforts, please consider <a href="https://ceph.io/en/foundation/join/">joining now</a>.</p>
</div>


           </div>
           
          </div>
          <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
        <a href="../multimds/" class="btn btn-neutral float-left" title="多活 MDS 守护进程的配置" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
        <a href="../eviction/" class="btn btn-neutral float-right" title="Ceph 文件系统客户端的驱逐" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>&#169; Copyright 2016, Ceph authors and contributors. Licensed under Creative Commons Attribution Share Alike 3.0 (CC-BY-SA-3.0).</p>
  </div>

   

</footer>
        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>